<template>
  <div  class="openShop" style="width: 100%">
    <div>
      <el-carousel :interval="2000" type="card" height="300px">
        <el-carousel-item v-for="item in dianshangs" :key="item.index">
          <img :src="item.url" />
        </el-carousel-item>
      </el-carousel>
    </div>

    <el-form ref="form" :model="form" label-width="85px">
      <el-form-item label="店主姓名">
        <el-input style="width: 300px" v-model="form.name"></el-input>
      </el-form-item>
      <el-form-item label="居民身份证">
        <el-input style="width: 300px" v-model="form.ID"></el-input>
      </el-form-item>
      <el-form-item label="店铺名称">
        <el-input style="width: 300px" v-model="form.shopName"></el-input>
      </el-form-item>
      <el-form-item label="售卖类型">
        <el-select v-model="form.region" placeholder="请选择售卖类型">
          <el-option label="电子产品" value="dianzichanpin"></el-option>
          <el-option label="衣物" value="yiwu"></el-option>
          <el-option label="零食" value="lingshi"></el-option>
          <el-option label="其他" value="qita"></el-option>
        </el-select>
      </el-form-item>

      <div class="IdPositive">
        <el-upload
          class="avatar-uploader"
          action="https://jsonplaceholder.typicode.com/posts/"
          :show-file-list="false"
          :on-success="handleAvatarSuccess"
          :before-upload="beforeAvatarUpload"
        >
          <img v-if="imageUrl" :src="imageUrl" class="avatar" />
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          <p>上传身份证正面</p>
        </el-upload>
      </div>

      <div class="IdOrderSide">
        <el-upload
          class="avatar-uploader"
          action="https://jsonplaceholder.typicode.com/posts/"
          :show-file-list="false"
          :on-success="handleAvatarSuccess"
          :before-upload="beforeAvatarUpload"
        >
          <img v-if="imageUrl" :src="imageUrl" class="avatar" />
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          <p>上传身份证国徽面</p>
        </el-upload>
      </div>

      <el-form-item>
        <el-button type="primary" @click="onSubmit">立即开通</el-button>
        <el-button @click="returnDefault">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        ID: "",
        name: "",
        shopName: "",
        region: "",
        date1: "",
        date2: "",
        delivery: false,
        type: [],
        resource: "",
        desc: "",
      },
      dianshangs: [
        { url: require("@/views/imgs/dianshang1.webp") },
        { url: require("@/views/imgs/dianshang2.webp") },
        { url: require("@/views/imgs/dianshang3.webp") },
        { url: require("@/views/imgs/dianshang4.webp") },
        { url: require("@/views/imgs/dianshang5.webp") },
      ],
      imageUrl: '',
    };
  },
  methods: {
    onSubmit() {
      console.log("submit!");
      this.$message.error("开店功能尚未开发完全，敬请期待！！！")
    },
    returnDefault(){
        this.$router.push('/default')
    },
    handleAvatarSuccess(res, file) {
        this.imageUrl = URL.createObjectURL(file.raw);
      },
      beforeAvatarUpload(file) {
        const isJPG = file.type === 'image/jpeg';
        const isLt2M = file.size / 1024 / 1024 < 2;

        if (!isJPG) {
          this.$message.error('上传头像图片只能是 JPG 格式!');
        }
        if (!isLt2M) {
          this.$message.error('上传头像图片大小不能超过 2MB!');
        }
        return isJPG && isLt2M;
      }
    },
};
</script>

<style scoped>
.el-carousel__item h3 {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 200px;
  margin: 0;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}
img {
  width: 100%;
  height: 100%;
}

.avatar-uploader .el-upload {
  border: 1px dashed #0f0a0a;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 300px;
  height: 150px;
  line-height: 150px;
  text-align: center;
}
.avatar {
  width: 300px;
  height: 150px;
  display: block;
}
.IdOrderSide{
    margin-left: 400px;
    margin-top: -201px;
}

</style>